﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Validation;

namespace CNdotnet.Ezsocio.Core.Validations
{
    public static class ValidationExtensions
    {
        public static bool Validate<TEntity>(this IValidated entity) where TEntity : IValidated
        {
            bool isValid = true;
            ValidationResults results = Validation.Validate<TEntity>((TEntity)entity);
            if (!results.IsValid)
            {
                entity.ValidationResults = results;
                isValid = false;
            }
            return isValid;
        }
    }
}
